home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.09 Sep 93 / Programmer's Challenge / TileWindows.c < prev   
Encoding:
C/C++ Source or Header  |  1993-07-12  |  2.8 KB  |  117 lines  |  [TEXT/GEOL]

  1. /*----------------------------------------------------
  2. TileWindows
  3. by Raffi Kasparian
  4. ----------------------------------------------------*/
  5. #define StackingOffset 10
  6.  
  7. void TileWindows(enclosingRectPtr, windowPtrArray,
  8.                  windowCount, pixelsBetween,
  9.                  minHorzSize, minVertSize)
  10.  
  11. Rect            *enclosingRectPtr;
  12. WindowPtr       windowPtrArray[];
  13. unsigned short  windowCount;
  14. unsigned short  pixelsBetween;
  15. unsigned short  minHorzSize;
  16. unsigned short  minVertSize;
  17.  
  18. #define mx minHorzSize
  19. #define my minVertSize
  20. #define d  pixelsBetween
  21.  
  22. #define struc  ((WindowPeek)(windowPtrArray[num]))->strucRgn
  23. #define strucL (**struc).rgnBBox.left
  24. #define strucT (**struc).rgnBBox.top
  25. #define strucR (**struc).rgnBBox.right
  26. #define strucB (**struc).rgnBBox.bottom
  27.  
  28. #define cont  ((WindowPeek)(windowPtrArray[num]))->contRgn
  29. #define contL (**cont).rgnBBox.left
  30. #define contT (**cont).rgnBBox.top
  31. #define contR (**cont).rgnBBox.right
  32. #define contB (**cont).rgnBBox.bottom
  33.  
  34. #define pBits  windowPtrArray[num]->portBits.bounds
  35. #define pBitsL pBits.left
  36. #define pBitsT pBits.top
  37. #define pBitsR pBits.right
  38. #define pBitsB pBits.bottom
  39.  
  40. #define pRect  windowPtrArray[num]->portRect
  41. #define pRectL pRect.left
  42. #define pRectT pRect.top
  43. #define pRectR pRect.right
  44. #define pRectB pRect.bottom
  45.  
  46. {
  47.  register short dL, dT, dR, dB, BR, x, y, maxx, maxy,
  48.                 num, rL, rT, rR, rB;
  49.  Rect           er = *enclosingRectPtr;
  50.  
  51. #define erL er.left
  52. #define erT er.top
  53. #define erR er.right
  54. #define erB er.bottom
  55.  
  56.  num = 0;
  57.  
  58.  while (true) {
  59.  
  60.   maxy = (erB - erT + d)/(my + d);
  61.   maxx = (erR - erL + d)/(mx + d);
  62.   if ((BR = maxx * maxy) > windowCount) {
  63.    maxx = (windowCount - 1) / maxy + 1;
  64.    maxy = (windowCount - 1) / maxx + 1;
  65.    BR = windowCount;
  66.   }
  67.   BR--;
  68.  
  69.   if (num <= BR) {
  70.    mx = ((erR - erL) - ((maxx - 1) * d)) / maxx;
  71.    my = ((erB - erT) - ((maxy - 1) * d)) / maxy;
  72.   }
  73.  
  74.   rT = erT - (my + d);
  75.   for (y = 1; y <= maxy; y++) {
  76.    rL = erL - (mx + d);
  77.    rT += my + d;
  78.    rB = (y == maxy) && (num <= BR) ? erB : rT + my;
  79.    for (x = 1; x <= maxx; x++, num++) {
  80.  
  81.     rL += mx + d;
  82.     rR = ((x == maxx) && (num <= BR)) ||
  83.       (num == BR) ? erR : rL + mx;
  84.  
  85.     dL = rL - strucL;
  86.     dT = rT - strucT;
  87.     dR = rR - strucR;
  88.     dB = rB - strucB;
  89.  
  90.     SetRectRgn(struc, rL, rT, rR, rB);
  91.     SetRectRgn(cont, contL + dL, contT + dT,
  92.       contR + dR,  contB + dB);
  93.       
  94.     pBitsL -= dL;
  95.     pBitsT -= dT;
  96.     pBitsR -= dL;
  97.     pBitsB -= dT;
  98.  
  99.     pRectR = contR - contL + pRectL;
  100.     pRectB = contB - contT + pRectT;
  101.  
  102.     if (num == windowCount - 1) {
  103.      PaintBehind((WindowPeek)FrontWindow(),
  104.        GrayRgn);
  105.      CalcVisBehind((WindowPeek)FrontWindow(),
  106.        GrayRgn);
  107.      return;
  108.     }
  109.    }
  110.   }
  111.   if (erR - erL - StackingOffset >= mx)
  112.    erL += StackingOffset;
  113.   if (erB - erT - StackingOffset >= my)
  114.    erT += StackingOffset;
  115.  }
  116. }
  117.